/*
 * @Author: 李石
 * @Date: 2024-05-20 08:09:08
 * @LastEditors: lishi
 * @LastEditTime: 2024-05-22 19:47:20
 * @Description: 
 * Copyright (c) 2024 by ${lishi0105@163.com}, All Rights Reserved. 
 */
#ifndef __COMMON_UTIL_H_
#define __COMMON_UTIL_H_

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

#include <stdio.h>
#ifndef __FILENAME__
#define __FILENAME__                                                         \
    (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \
                                      : __FILE__)
#endif

#ifndef DBGI
#define DBGI(format...)                                       \
    do {                                                      \
        printf("\033[0;32m[%s:%d] ", __FILENAME__, __LINE__); \
        printf(format);                                       \
        printf("\033[0;39m");                                 \
    } while (0)
#endif

#ifndef DBGE
#define DBGE(format...)                                       \
    do {                                                      \
        printf("\033[0;31m[%s:%d] ", __FILENAME__, __LINE__); \
        printf(format);                                       \
        printf("\033[0;39m");                                 \
    } while (0)
#endif

void bin_to_hexstr(const unsigned char *in_bin, size_t len, char *out_str);

void hexstr_to_bin(const char *in_str, unsigned char *out_bin, size_t *len);

int isValidIPv4(const char *ip);

int isValidIPv6(const char *ipv6);

void get_usage(long *virtual_memory, long *physical_memory, double *cpu) ;

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

#endif  // __COMMON_UTIL_H_